//
//  ContactInfoController.m
//  通讯录LV2.0
//
//  Created by dllo on 16/8/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ContactInfoController.h"
#import "ContactRow.h"

@interface ContactInfoController ()<UIGestureRecognizerDelegate>

@property (weak, nonatomic) IBOutlet UILabel *nameLogo;

@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;


@property (weak, nonatomic) IBOutlet UITextField *nameTextField;

@property (weak, nonatomic) IBOutlet UITextField *familyTextField;

@property (weak, nonatomic) IBOutlet UIButton *editBtn;


@end

@implementation ContactInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTap];
    
    self.navigationController.navigationBarHidden = YES;
    _nameLogo.text = _model.name;
    _nameTextField.text = _model.name;
    _nameTextField.borderStyle = UITextBorderStyleNone;
    _familyTextField.text = _model.family;
    _familyTextField.borderStyle = UITextBorderStyleNone;
    _phoneNumber.text = _model.phoneNumber;
    _phoneNumber.borderStyle = UITextBorderStyleNone;
    
    _modelOfChange = [[ContactRow alloc]init];
    _modelOfChange.name = _model.name;
    _modelOfChange.family = _model.family;
    _modelOfChange.phoneNumber = _model.phoneNumber;
    
    
}

- (IBAction)editAction:(id)sender {
    self.nameTextField.enabled = YES;
    self.phoneNumber.enabled = YES;
    [self.phoneNumber becomeFirstResponder];
    self.familyTextField.enabled = YES;
}

- (IBAction)saveAction:(id)sender {
    _modelOfChange.name = _nameTextField.text;
    _modelOfChange.family = _familyTextField.text;
    _modelOfChange.phoneNumber = _phoneNumber.text;
    
    
    
}

- (IBAction)returnAction:(id)sender {
    self.navigationController.viewControllers = @[self, self.navigationController.viewControllers[0]];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
}


#pragma mark - 手势
- (void)createTap
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];
}

- (void)tapAction:(UITapGestureRecognizer *)tap
{
    [_nameTextField resignFirstResponder];
    [_familyTextField resignFirstResponder];
    [_phoneNumber resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
